/**
 * 
 */
package grid;

import java.util.*;

/**
 * @author Darko
 *
 */
public abstract class Node {

    protected String name;

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }
    protected String executable;

    public String getExecutable() {
        return this.executable;
    }

    public void setExecutable(String executable) {
        this.executable = executable;
    }
    protected String argumentsPrefix;

    public String getArgumentsPrefix() {
        return this.argumentsPrefix;
    }

    public void setArgumentsPrefix(String argumentsPrefix) {
        this.argumentsPrefix = argumentsPrefix;
    }

    public abstract String getArguments();

    public abstract String getInputSandbox();

    public abstract String getOutputSandbox();

    public String getStdOutput() {
        return getName() + ".out";
    }

    public String getStdError() {
        return getName() + ".err";
    }

    @Override
    public String toString() {
        StringBuilder buffer = new StringBuilder();
        buffer.append(this.name + " = [\n");
        buffer.append("description = [\n");
        buffer.append("JobType = \"Normal\";\n");
        buffer.append("Executable = \"" + getExecutable() + "\";\n");
        buffer.append("Arguments = " + getArguments() + ";\n");
        buffer.append("StdOutput = \"" + getStdOutput() + "\";\n");
        buffer.append("StdError = \"" + getStdError() + "\";\n");
        String input = getInputSandbox();
        if (input != null) {
            buffer.append("InputSandbox = " + input + ";\n");
        }
        String output = getOutputSandbox();
        if (output != null) {
            buffer.append("OutputSandbox = " + output + ";\n");
        }
        buffer.append("];\n");
        buffer.append("];\n");

        return buffer.toString();
    }
    List<Node> inputNodes = new LinkedList<Node>();
    List<Node> outputNodes = new LinkedList<Node>();

    public void add(int index, Node element) {
        this.inputNodes.add(index, element);
    }

    public boolean addInputNode(Node e) {
        return this.inputNodes.add(e);
    }

    public boolean addAllInputNodes(Collection<? extends Node> c) {
        return this.inputNodes.addAll(c);
    }

    public boolean addAllInputNodes(int index, Collection<? extends Node> c) {
        return this.inputNodes.addAll(index, c);
    }

    public void clearInputNodes() {
        this.inputNodes.clear();
    }

    public boolean containsInputNode(Node o) {
        return this.inputNodes.contains(o);
    }

    public boolean containsAllInputNodes(Collection<? extends Node> c) {
        return this.inputNodes.containsAll(c);
    }

    public Node getInputNodes(int index) {
        return this.inputNodes.get(index);
    }

    public int indexOfInputNodes(Node o) {
        return this.inputNodes.indexOf(o);
    }

    public boolean isEmptyInputNodes() {
        return this.inputNodes.isEmpty();
    }

    public Node remove(int index) {
        return this.inputNodes.remove(index);
    }

    public boolean removeInputNodes(Node o) {
        return this.inputNodes.remove(o);
    }

    public boolean removeAllInputNodes(Collection<? extends Node> c) {
        return this.inputNodes.removeAll(c);
    }

    public boolean retainAllInputNodes(Collection<? extends Node> c) {
        return this.inputNodes.retainAll(c);
    }

    public Node setInputNodes(int index, Node element) {
        return this.inputNodes.set(index, element);
    }

    public int sizeInputNodes() {
        return this.inputNodes.size();
    }

    public boolean addOutputNodes(Node e) {
        return this.outputNodes.add(e);
    }

    public boolean addAllOutputNodes(Collection<? extends Node> c) {
        return this.outputNodes.addAll(c);
    }

    public boolean addAllOutputNodes(int index, Collection<? extends Node> c) {
        return this.outputNodes.addAll(index, c);
    }

    public void clearOutputNodes() {
        this.outputNodes.clear();
    }

    public boolean containsOutputNodes(Node o) {
        return this.outputNodes.contains(o);
    }

    public boolean containsAllOutputNodes(Collection<? extends Node> c) {
        return this.outputNodes.containsAll(c);
    }

    public Node getOutputNodes(int index) {
        return this.outputNodes.get(index);
    }

    public int indexOfOutputNodes(Node o) {
        return this.outputNodes.indexOf(o);
    }

    public boolean isEmptyOutputNodes() {
        return this.outputNodes.isEmpty();
    }

    public boolean removeOutputNodes(Node o) {
        return this.outputNodes.remove(o);
    }

    public boolean removeAllOutputNodes(Collection<? extends Node> c) {
        return this.outputNodes.removeAll(c);
    }

    public boolean retainAllOutputNodes(Collection<? extends Node> c) {
        return this.outputNodes.retainAll(c);
    }

    public Node setOutputNodes(int index, Node element) {
        return this.outputNodes.set(index, element);
    }

    public int sizeOutputNodes() {
        return this.outputNodes.size();
    }
}
